package org.dandsoft.blackbox.logger;

import java.util.Map;
import java.util.Hashtable;
import java.util.Collections;

/**
 * User: dvilyuzhanin
 * Date: 21.01.2009 14:02:31
 */
public class Message {

    private MessageLevel level;
    private String groupName;
    private Map<String, Object> parameters;
    private String description;

    public Message(MessageLevel level, String groupName, Map<String, Object> parameters, String description) {
        this.level = level;
        this.groupName = groupName;
        this.parameters = Collections.unmodifiableMap(parameters);
        this.description = description;
    }

    public MessageLevel getLevel() {
        return level;
    }

    public String getGroupName() {
        return groupName;
    }

    public Map<String, Object> getParameters() {
        return parameters;
    }

    public String getDescription() {
        return description;
    }

    public static MessageBuilder createBuilder(MessageLevel level, String groupName, String description) {
        return new MessageBuilder(level, groupName, description);
    }

    public static class MessageBuilder {

        private MessageLevel level;
        private String groupName;
        private String description;
        private Hashtable<String, Object> parameters = new Hashtable<String, Object>();

        public MessageBuilder(MessageLevel level, String groupName, String description) {
            this.level = level;
            this.groupName = groupName;
            this.description = description;
        }

        public MessageBuilder addParameter(String name, Object value) {
            parameters.put(name, value);
            return this;
        }

        public Message build() {
            Message result = new Message(level, groupName, parameters, description);
            return result;
        }
    }

}
